package io;

import java.io.*;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;

public class Test03 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        File dir = new File(".");//获取当前目录中所有的子项
        File[] subs =dir.listFiles(f -> f.getName().endsWith(".obj"));//筛选满足条件结尾为“.obj”结尾的文件
        for (int i = 0; i < subs.length; i++) {//遍历数组
            File sub = subs[i];//将数组赋给sub
            FileInputStream fis = new FileInputStream(sub);//将数组读出
            ObjectInputStream ois = new ObjectInputStream(fis);//对象流读出
            Object obj = ois.readObject();//读出对象

           if (obj instanceof User) {//判断obj对象是否属于User类
                User user = (User) obj;//将obj转为user类型
                System.out.println(user);//输出user
                ois.close();//关闭流
                System.out.println("完成");

            }
        }
    }
}